USE GESTION2
go

IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO') IS NOT NULL 
   BEGIN
      DROP PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO 
      IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO') 
      IS
      NOT NULL 
         PRINT 
         '<<< FAILED DROPPING PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO >>>'
      ELSE
         PRINT 
         '<<< DROPPED PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO >>>' 
   END
go

SET ANSI_NULLS ON
go

SET QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE WASP_D0005_CREA_TABLA_TIPO_CONTRATO 
AS
   IF EXISTS (
   SELECT * 
   FROM dbo.sysobjects 
   WHERE id = OBJECT_ID(N'[tip]') 
   AND OBJECTPROPERTY(id, N'IsUserTable') = 1) DROP TABLE [tip] 
   SELECT Z07374CT1,
      Z07374CT2,
      MAX(Z07374CON) Z07374CON,
      z07354cod
   INTO dbo.tip 
   FROM z07374 a(nolock), z07369 b(nolock) 
   WHERE a.Z07374CT1 = b.Z07369CT1 
   AND a.Z07374PG1 = b.Z07369PG1 
   AND a.Z07374CT2 = b.Z07369CT2 
   AND a.Z07374PG2 = b.Z07369PG2 
   AND b.Z07369EST = 'S' /*Z07374CT1 = 500000210 and Z07374CT2 = 11629944 and Z07374CON = '1997-01-02 00:00:00.000'*/
   GROUP BY Z07374CT1, Z07374CT2, z07354cod
go



SET ANSI_NULLS OFF
go

SET QUOTED_IDENTIFIER OFF
go

IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO') IS NOT NULL 
   PRINT '<<< CREATED PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO >>>' 
ELSE
   PRINT 
   '<<< FAILED CREATING PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CONTRATO >>>'
go
